const path = require('path')

const CleanWebpackPlugin = require('clean-webpack-plugin');

function resolve(dir) {
  return path.join(__dirname, dir)
}

module.exports = {
  //entry: './src/app.js',
  //entry: ['./src/app.js', './src/index.js'],
  entry: {
    app: './src/app.js',
    index: './src/index.js'
  },
  output:{
    path: resolve('dist') ,
    filename: '[name].js'
  },
  module: { //loader
    rules:[
      {
        test: /\.css$/,
        //use:['style-loader','css-loader']
        use:[
          {
            loader: 'style-loader',
            options: {
              sourceMap: true
            }
          },
          {
            loader: 'css-loader',
            options: {
              sourceMap: true
            }
          }
        ]
      },
      {
        test:/\.scss$/,
        use:['style-loader','css-loader','sass-loader']
      },
      //file-loader
      //url-loader
      {
        test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
        loader: 'url-loader',
        options: {
          limit: 10000,  // 字节 1024字节=1kb 1024kb=1m
          name: 'img/[name].[hash:7].[ext]'
        }
      }
    ]
  },  
  plugins:[
    new CleanWebpackPlugin(['dist'])
  ]
}